import 'package:finance_app/src/entities/transaction_entity.dart';

transactionEntityFromJson(TransactionEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['transaction_type'] != null) {
		data.transactionType = json['transaction_type'].toString();
	}
	if (json['transactionable_type'] != null) {
		data.transactionableType = json['transactionable_type'].toString();
	}
	if (json['transactionable_id'] != null) {
		data.transactionableId = json['transactionable_id'] is String
				? int.tryParse(json['transactionable_id'])
				: json['transactionable_id'].toInt();
	}
	if (json['contact_id'] != null) {
		data.contactId = json['contact_id'] is String
				? int.tryParse(json['contact_id'])
				: json['contact_id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['number'] != null) {
		data.number = json['number'];
	}
	if (json['is_overdue'] != null) {
		data.isOverdue = json['is_overdue'] is String
				? int.tryParse(json['is_overdue'])
				: json['is_overdue'].toInt();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['tax_amount'] != null) {
		data.taxAmount = json['tax_amount'] is String
				? num.tryParse(json['tax_amount'])
				: json['tax_amount'];
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['unpaid'] != null) {
		data.unpaid = json['unpaid'] is String
				? num.tryParse(json['unpaid'])
				: json['unpaid'];
	}
	if (json['issued_at'] != null) {
		data.issuedAt = json['issued_at'].toString();
	}
	if (json['due_at'] != null) {
		data.dueAt = json['due_at'];
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_by'] != null) {
		data.createdBy = json['created_by'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['employee_id'] != null) {
		data.employeeId = json['employee_id'].toString();
	}
	return data;
}

Map<String, dynamic> transactionEntityToJson(TransactionEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['transaction_type'] = entity.transactionType;
	data['transactionable_type'] = entity.transactionableType;
	data['transactionable_id'] = entity.transactionableId;
	data['contact_id'] = entity.contactId;
	data['name'] = entity.name;
	data['number'] = entity.number;
	data['is_overdue'] = entity.isOverdue;
	data['currency_code'] = entity.currencyCode;
	data['tax_amount'] = entity.taxAmount;
	data['total'] = entity.total;
	data['unpaid'] = entity.unpaid;
	data['issued_at'] = entity.issuedAt;
	data['due_at'] = entity.dueAt;
	data['status'] = entity.status;
	data['created_by'] = entity.createdBy;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['employee_id'] = entity.employeeId;
	return data;
}